<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增信箱')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-mail-add">
            <h4 class="form-header h4">信箱信息</h4>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">邮件编号：</label>
                <div class="col-sm-8">
                    <input name="emailId" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">删除状态：</label>
                <div class="col-sm-8">
                    <input name="emailDelete" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">删除标志：</label>
                <div class="col-sm-8">
                    <input name="delFlag" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">更新人：</label>
                <div class="col-sm-8">
                    <input name="updatedBy" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">更新时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="updatedTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <h4 class="form-header h4">邮件 信息</h4>
            <div class="row">
                <div class="col-sm-12">
                    <button type="button" class="btn btn-white btn-sm" onclick="addRow()"><i class="fa fa-plus"> 增加</i></button>
                    <button type="button" class="btn btn-white btn-sm" onclick="sub.delRow()"><i class="fa fa-minus"> 删除</i></button>
                    <div class="col-sm-12 select-table table-striped">
                        <table id="bootstrap-table"></table>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "eamil/mail"
        $("#form-mail-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-mail-add').serialize());
            }
        }

        $("input[name='updatedTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(function() {
            var options = {
                pagination: false,
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                sidePagination: "client",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'index',
                    align: 'center',
                    title: "序号",
                    formatter: function (value, row, index) {
                    	var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                    	return columnIndex + $.table.serialNumber(index);
                    }
                },
                {
                    field: 'emailName',
                    align: 'center',
                    title: '邮件名称',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='emailLetterList[%s].emailName' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'emailType',
                    align: 'center',
                    title: '类型',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='emailLetterList[%s].emailType' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'emailTime',
                    align: 'center',
                    title: '时间',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='emailLetterList[%s].emailTime' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'userSend',
                    align: 'center',
                    title: '发件人邮箱',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='emailLetterList[%s].userSend' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'userReception',
                    align: 'center',
                    title: '收件人邮箱',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='emailLetterList[%s].userReception' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'emailFile',
                    align: 'center',
                    title: '附件',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='emailLetterList[%s].emailFile' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'emailText',
                    align: 'center',
                    title: '文本',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='emailLetterList[%s].emailText' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'emailCheck',
                    align: 'center',
                    title: '查看状态',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='emailLetterList[%s].emailCheck' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'emailDraft',
                    align: 'center',
                    title: '草稿状态',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='emailLetterList[%s].emailDraft' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'updatedBy',
                    align: 'center',
                    title: '更新人',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='emailLetterList[%s].updatedBy' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'updatedTime',
                    align: 'center',
                    title: '更新时间',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='emailLetterList[%s].updatedTime' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var value = $.common.isNotEmpty(row.index) ? row.index : $.table.serialNumber(index);
                        return '<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="sub.delRowByIndex(\'' + value + '\')"><i class="fa fa-remove"></i>删除</a>';
                    }
                }]
            };
            $.table.init(options);
        });

        function addRow() {
            var count = $("#" + table.options.id).bootstrapTable('getData').length;
            var row = {
                index: $.table.serialNumber(count),
                emailName: "",
                emailType: "",
                emailTime: "",
                userSend: "",
                userReception: "",
                emailFile: "",
                emailText: "",
                emailCheck: "",
                emailDraft: "",
                updatedBy: "",
                updatedTime: "",
            }
            sub.addRow(row);
        }
    </script>
</body>
</html>